//This is file contains functions of the normal mode

#include "easybutterfly.h"
#include "macro.h"

void person_counter(void){

	//this function will count how many people are inside and how many get out of the place
	BRIGHTNESS(light)
	if(light > MIN_intensity1){		//checking if is inside the range

		light1 = 1;
		inout = (light2)? inout : 1;	//this variable allows to know whether a person is going IN or OUT

	}
	
	VOLTAGE(light)
	if(light > MIN_intensity2){		//checking the second LDR sensor

		light2 = 1;
		inout = (light1)? inout : 2;

	}

	if((light1 == 2) && (light1 == 1)){
		counter++;		//increase the people counter
		light1 = 0;
		light2 = 0;
		inout = 0;
	}else if((inout == 1) && (light2 == 1)){
		counter = (counter <= 0)? 0 : counter - 1;		//decrease the people counter
		light1 = 0;
		light2 = 0;
		inout = 0;
	}
}

void illumination_control(void){

	//this function allows to control the intensity of the light
	//through a simulated PWM
	BRIGHTNESS(light)	//Measuring of ambient light
	int limite = 10;	//This represent the time in which the lights are turned on
	int limite2 = limite*(100-light);	//This represent the time in which the lights are turned off
	light_ON;	//Turn on the lights
	for(int i=0; i<=limite; i++);	//waiting Activated time
	light_OFF;	//Turn off the lights
	for(int i=0; i<=limite2; i++);	//waiting Deactivated time

}